// 1.加载核心模块
const http=require("http");
const fs=require("fs");


// 2.创建服务器功能函数
const server=http.createServer(function(request,response){
    let path=request.url;//请求路径
    console.log(path);
    switch(path){
        case "/":
            let buffer1=fs.readFileSync("./public/home.html");
            let str1=buffer1.toString();
            response.end(str1);
            break;
        case "/user":
            let buffer2=fs.readFileSync("./public/user.html");
            let str2=buffer2.toString();
            response.end(str2);
            break;
        case "/favicon.ico":
            let buffer3=fs.readFileSync("./public/img/01.png");
            response.end(buffer3);
            break;
        default:
            let buffer4=fs.readFileSync("./public/404.html");
            let str4=buffer4.toString();
            response.end(str4);
    }
    
   
}); 


// 3.启动服务器
server.listen(3000);